<%@ taglib uri="/WEB-INF/displaytag-12.tld" prefix="display" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
/*
Modified by Arun on aug 1

	com.ba360.portal.database.dbo.User user = (com.ba360.portal.database.dbo.User)session.getAttribute("USER");
	*/
	com.ba360.portal.database.dbo.User_23Feb09 user = (com.ba360.portal.database.dbo.User_23Feb09)session.getAttribute("USER");
	if (user==null)
	{
	request.setAttribute("USER_NOT_LOGGED_IN","UNPLUGGED");
	%>
	
	<jsp:forward page="/portal/login.do"/>
	
<%}%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<style type="text/css">
 td.c4 {background-color: #FFFFFF}
 div.c3 {text-align: justify}
 div.c2 {text-align: center}
 td.c1 {background-color: #00105E}
select{width:30%}
</style>
<script>
	function cityaction()
	{
	var selObj = document.getElementById('city');
	var selIndex = selObj.selectedIndex;
	document.getElementById('city_id').value=selObj.options[selIndex].value;
	document.getElementById('City').value=selObj.options[selIndex].text;	
	 if(selObj.options[selIndex].value == "9")
	 {
	 	document.getElementById('other').value="";
	 	document.getElementById('othercity').style.display = "block";
	 }
	 else
	 {
	  document.getElementById('other').value="";
	  document.getElementById('othercity').style.display = "none";
	 }
	}
</script>
</head>
<body>
<%
	String choice = request.getParameter("Action");

	if (choice!=null && choice.equals("Next"))
	{
		String postingType = request.getParameter("PostingType");
		request.setAttribute("category_id",postingType);
		String catType     = request.getParameter("CatType");	
		String city 	   = request.getParameter("city");
		String other 	   = request.getParameter("other");
		
		if (postingType==null || postingType.equals("0"))
		{
			request.setAttribute("Error","Posting type not selected");
		}
		else if( (city.equals("9")) && (other.equals("") || other.equals(null)))
		{
			request.setAttribute("Error","Other city cannot be empty");
		}
		else if (city==null || city.equals(""))
		{

			request.setAttribute("Error","City not selected");
		}
		else if (postingType!=null && !postingType.equals("0") && city!=null && !city.equals(""))
		{						
			String url = "../portal/postadv.do?category_id="+postingType+"&CatType="+catType+"&City="+city;	
%>
			<jsp:forward page="<%=url%>"/>
<%		}
	} 
	else if (choice!=null && choice.equals("Cancel"))
	{
%>
	<jsp:forward page="../portal/myadlist.do"/>
<% 
}
%>

<%						
	java.sql.Connection conn = null;
	java.sql.Statement  stat = null;
	Class.forName( "com.mysql.jdbc.Driver");
	conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/ba3602_classifiedsdb","root","test" );
	//conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/ba3602_droikclassifieds","root","" );
	stat = conn.createStatement();						
%>
<form name="form1" method="get" action="../portal/NewAdv.do">
	<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td>
							<table width="100%"  border="0" cellspacing="0" cellpadding="0">
								<tr>									
									<td width="44%" valign="top">
										<jsp:include page="/jsp/top.jsp"/>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				
					<tr>
						<td class="c4" height="232" valign="top">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td width="100%" valign="top">
										<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
											<tr>
												<td width="86%" height="25" class="text style3"><span class="bluehead">Post An Ad</span></td>
												<td width="14%" class="text style3"> </td>
											</tr>
											<tr>
												<td colspan="2" class="text">
												<div class="c21"><img src="../images/line.jpg" width="1000" height="3" vspace="5" alt="** PLEASE DESCRIBE THIS IMAGE **"></div>
												</td>
											</tr>
											
											<tr valign="top">
												<td colspan="2" class="text">
													<div class="c3">
														<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
														<!--<tr>
															<td height="25" background="../images/bo_01.jpg">&nbsp;</td>
														</tr><tr>
																<td height="20" valign="top" background="../images/bo_02.jpg">--><td>
																	<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
																		<tr valign="bottom">
																			<td width="100%">
																				<table width="100%" border="0" cellspacing="0" cellpadding="0">
																					<tr>
																						<td colspan="3" align="center"><img src="../images/AdPage1.jpg"  alt="Step1"></td>
																					</td>
																					</tr>
																				</table>
																			</td>
																		</tr>
																	</table>
																</td>
															</tr>
															<tr>
																<!--<td height="151" valign="middle" background="../images/bo_02.jpg">--><td>
																	<table width="800" border="0" align="right" cellpadding="0" cellspacing="2">
																		<tr>
																			<td colspan="2" style="font-family: Tahoma, Arial;font-size: 12px;font-weight: bolder;color:RGB(24,120,204);">
																				<% if (request.getAttribute("Error")!=null)
																				   {
																					out.println(request.getAttribute("Error"));	
																				   }
																				%>
																			</td>
																		</tr>
																		<tr>
																			<td width="19%" height="30">Posting Type</td>
																			<td width="81%" height="30">
																				<select name="PostingType" id="PostingType" onChange="javascript:submit()"  class="field" >
																					<%		  
																						java.sql.ResultSet rs = stat.executeQuery("select name,category_id  from categories where par_category_id is null;");
																						String postingType = request.getParameter("PostingType");
																						int postingID=0;
																						
																						if (postingType!=null && postingType.length()>0 && !postingType.equals("0"))
																						{
																							postingID = Integer.parseInt(postingType);
																						} 
																						else 
																						{
																					%>
																							<option value="0" selected>--Select a Category--</option>
																					<%	}
																						while (rs.next())
																						{
																							String name = rs.getString(1);
																							int id = rs.getInt(2);
																					%>
																					<%
																						if (id==postingID )
																						{																							
																					%>
																							<option value="<%=id%>" selected><%=name%></option>
																					<%	}
																					        else 
																					        {
																					%>
																							<option value="<%=id%>"><%=name%></option>
																					<%
																						}
																					} 
																					%>
																				</select>
																			</td>
																		</tr>
																		<tr>
																			<td height="30">Sub Category type</td>
																			<td height="30">
																				<% if (postingID==0)
																				   {
																				%>
																					<select name="CatType" id="CatType" onChange="javascript:submit()" disabled='true'  class="field" >
																				<% }
																				%>
																				<% if (postingID!=0)
																				   {
																				%>
																				   	<select name="CatType" id="CatType" onChange="javascript:submit()"  class="field" >
																				<%
																						rs = stat.executeQuery("select name,category_id  from categories where par_category_id ="+postingID);
																						String subcategory_id = request.getParameter("CatType");
																						int subidCat=0;
																						
																						if (subcategory_id!=null)
																						{
																							subidCat = Integer.parseInt(subcategory_id);
																						}
																						while (rs.next())
																						{
																							String subname = rs.getString(1);
																							int subid = rs.getInt(2);
																				
																				%>
																				<%
																							if (subid==subidCat )
																							{
																				%>
																								<option value="<%=subid%>" selected><%=subname%></option>
																				<%			}
																						        else
																						        {
																				%>
																								<option value="<%=subid%>"><%=subname%></option>
																				<%
																							}
																						}
																				    }	
																				%>
																					</select>
																			</td>
																		</tr>
																		<tr>
																			<td height="30">City</td>
																			<td height="30">
																				<%							
																				if (postingID==0)
													         						   {         						   
													         						%>
													         						     <select name="city" id="city" onChange="cityaction()" disabled='true'  class="field" >         						     
													         						<% }    
													         						   else
													         						   {  
													         						  
													         						    %>
													         						     <select name="city" id="city" onChange="cityaction()"  class="field" >         						     
													         						<% }          													   
														         						   rs = stat.executeQuery("select city_id,cityname from lookup_city"); 
														         						   
														         						   while (rs.next())
														         						   {         		
															         						   int cityid = rs.getInt(1);
																						   String cityname = rs.getString(2);
																					%>
														         								<option value="<%=cityid%>"><%=cityname%></option>
														         					<%
														         						   }	         						    
														         					%>		
													         						    </select>
																			</td>																															<td>         
												         						          <input type="hidden" name="city_id" id="city_id" value=""/>						    	
												         						          <input type="hidden" name="City" id="City" value=""/>						    	
												         						    	  <span id="othercity" style="display:none">Other city :<Input class="field" type="text" name="other" id="other" value="" /></span>         						    	
												         						</td>
																		</tr>
																		<tr>
																			<td colspan="2" class="blu"> </td>
																		</tr>
																		<tr>
																			
																			<td colspan="2">
																			<input type="hidden" name="isedit" value="false">
																			<input type="image" src="../images/cancel.jpg" name="Action" value="Cancel" class="button">
																			<input type="image" src="../images/next.jpg" name="Action" value="Next" class="button">
																		</tr>
																	</table>
																</td>
															</tr>
															<tr>
																<td><!--<img src="../images/bo_03.jpg" width="725" height="16" alt="">--></td>
															</tr>
														</table>
													</div>
												</td>
											</tr>
										</table>
									</td>
									<td width="1" valign="top"></td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
						<jsp:include page="/jsp/footer.html"/>	
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
<%conn.close();%>

<script>
cityaction();
</script>
</body>
</html>	   			      						   
					